package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.ClassShopBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.view.MyGridView;
import cn.xfdzx.android.apps.shop.view.TagTextView;

/**
 * @author gzk
 * @date 2020/4/13 0013
 * description：新发地  分类  商铺
 */
public class XFDShopAdapter extends RecyclerView.Adapter<XFDShopAdapter.MyViewHolder> {

    private  ItemClickListener mItemClickListener;
    private  List<ClassShopBeen.DataBean> mList;
    private Context context;



    public XFDShopAdapter(Context context, List<ClassShopBeen.DataBean>list) {
        this.mList = list;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_xfd_shop, parent, false);
        MyViewHolder myHolder = new MyViewHolder(inflate);

        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {

        holder.ttvShop.setSingleTagAndContent("新发地",mList.get(position).getName(),R.drawable.d02c557_bg_r3,"#FFFFFFFF");

        holder.tvAddress.setText("地址："+mList.get(position).getAddress());
        holder.mgvXfdShop.setAdapter(new XFDShopAdapterGVAdapter(context,mList.get(position).getGoods()));
        holder.tvTheMain.setText("主营："+mList.get(position).getIntro());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Utils.isFastClick()) {
                    mItemClickListener.onItemClick(position);
                }
            }
        });


    }


    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.ttv_shop)
        TagTextView ttvShop;
        @BindView(R.id.tv_address)
        TextView tvAddress;
        @BindView(R.id.mgv_xfd_shop)
        MyGridView mgvXfdShop;
        @BindView(R.id.tv_the_main)
        TextView tvTheMain;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }


    public void setOnItemClickListener( ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}
